package com.lzz.aspects;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * AOP切面编程  添加aspectjweaver依赖
 * @author zhenzhen
 * @date 2018-12-17 下午7:33
 */
@Aspect
@Component
@Slf4j
public class TimeAspect {
    @Around("execution(* com.lzz.controller.TestController.*(..))")
    public Object handleControllerMethod(ProceedingJoinPoint pjp) throws Throwable {
        log.info("AOP TimerAspect start");
        Long start = System.currentTimeMillis();

        // 获取方法参数
        Object[] args = pjp.getArgs();
        for (Object arg : args) {
            log.info("arg is: "+ arg);
        }

        // 执行切面方法，返回值就是切面方法的返回值
        Object result = pjp.proceed();
        // log.info("AOP TimeAspect result is:" +result.toString());
        log.info("AOP timeAspect use time: " + (System.currentTimeMillis()-start));
        log.info("AOP TimeAspect end");

        return result;
    }
}
